//////////////////////////////////////////////////////////////////
// Function file for Armed Assault II
// Created by: Marker and Melbo 
// 显示准星目标的单位和载具信息--K1优化
// images文件夹下是载具图标资源文件
//////////////////////////////////////////////////////////////////
  
if (isDedicated) exitWith {};
  
//#define _debug true   //UNCOMMENT TO RUN DEBUG, WILL SHOW TIME TAKEN AND ANY LOSS OF FRAMES
#define _refresh .34
#define _distance 300

while{true}do{
    _target = cursorTarget;
if (!isNull _target) then {
    #ifdef _debug
    _initTime = diag_tickTime;
    _frameNo = diag_frameNo;
    #endif
    _blank = " ";
    if (_target isKindOf "CaManBase" && {player == vehicle player}) then{
        if (side _target == side player && {player distance _target < _distance})then{
			_weaponsplayer = currentWeapon _target;
			_nameString = "<t size='0.5' shadow='2' color='#7FFF00'>" + format['%1 %2',_target getVariable['unitname', if(alive _target)then[{name _target},{""}]]] + "</t>";
			_weaponsplayername = getText (configFile >> "CfgWeapons" >> _weaponsplayer >> "displayname");
			_weaponspic = getText (configFile >> "CfgWeapons" >> _weaponsplayer >> "picture");
			_rank = [_target,"displayNameShort"] call BIS_fnc_rankParams;
			_nameString = format ["<t size='0.5' color='#f0e68c'>%4. </t><t size='0.5' color='#f0e68c'>%1</t><br/><t size='0.5' color='#f0e68c'>%2</t><br/><img size='0.8' image='%3'/><br/>",if(alive _target)then[{name _target},{""}], _weaponsplayername,_weaponspic,_rank];
			[_nameString,0.5,0.9,_refresh,0,0,3] spawn bis_fnc_dynamicText;
        }; //playerSide
    };
    if ((_target isKindOf "Car" || {_target isKindOf "Ship"} || {_target isKindOf "air"} || {_target isKindOf "Tank"} || {_target isKindOf "Motorcycle"}) && {player == vehicle player}) then {
        if (side _target == side player && {player distance _target < _distance} && {(count crew _target) > 0}) then {
			_label = getText (configFile >> "CfgVehicles" >> typeOf _target >> "displayName");
			_picture = getText (configFile >> "cfgVehicles" >> typeOf _target >> "picture");
			_driver = driver _target;
			_gunner =  gunner _target;
			_commander = commander _target;
			_driver = if(alive _driver)then{name _driver}else{"无驾驶员"};
			_gunner = if(alive _gunner)then{name _gunner}else{"无炮手"};
			_commander = if(alive _commander)then{name _commander}else{"无指挥官"};
			_freePassengerSpaces = _target emptyPositions "cargo";
			_passengerSpaces = getNumber (configFile >> "CfgVehicles" >> typeOf _target >> "transportSoldier");

			_driver = format ["%1 %2 <img size='0.35' color='#7FFF70' image='images\crew_driver.paa'/><br/>",_blank, _driver];
			_gunner = format ["%1 %2 <img size='0.35' color='#7FFF70' image='images\crew_gunner.paa'/><br/>",_blank,_gunner];
			_commander = format ["%1 %2 <img size='0.35' color='#7FFF70' image='images\crew_commander.paa'/><br/>",_blank,_commander];
			_cargo = format ["%1 / %2 <img size='0.35' color='#7FFF70' image='images\crew_cargo.paa'/><br/>",_freePassengerSpaces, _passengerSpaces];
 
			_printname = format ["<t size='0.5' color='#f0e68c'>%1 / </t><img size='0.45' image='%5'/><br/><t size='0.5' color='#f0e68c'>%2</t><t size='0.5' color='#f0e68c'>%3</t><t size='0.5' color='#f0e68c'>%6</t><t size='0.5' color='#f0e68c'>%4</t>", _label, _driver, _gunner, _cargo,_picture,_commander];

            [_printname,0.5,0.9,_refresh,0,0,3] spawn bis_fnc_dynamicText;
        };
    };
    
    #ifdef _debug
    player sidechat format["time: %1, frames: %2",_initTime - diag_tickTime,_frameNo - diag_frameNo];
    #endif
};
    sleep _refresh;
};
